package com.hundun;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import weaver.interfaces.schedule.BaseCronJob;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * User: xf
 * Date: 12-11-14
 * Time: 下午4:11
 */
public class GMJob extends BaseCronJob {
    @Override
    public void execute() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        try {
            String rootpath = GMTable.class.getResource("/").toURI().getPath();
            //System.out.printf("rootpath:"+rootpath);
            Properties props = new Properties();
            InputStream in = new FileInputStream(rootpath + "../WEB-INF/prop/weaver.properties");
            props.load(in);
            String driver = props.getProperty("DriverClasses");
            String url = props.getProperty("ecology.url");
            String username = props.getProperty("ecology.user");
            String password = props.getProperty("ecology.password");
            DriverManagerDataSource ds = new DriverManagerDataSource();
            ds.setDriverClassName(driver);
            ds.setUrl(url);
            ds.setUsername(username);
            ds.setPassword(password);
            jdbcTemplate.setDataSource(ds);
            jdbcTemplate.update("delete from hundun_guimo");
            List<Map> pdidlist = jdbcTemplate.queryForList("select id from formtable_main_116");
            for(Map pdidmap:pdidlist){
                String pdid=pdidmap.get("id").toString();
                GMTable gmTable=new GMTable(pdid,true);
                gmTable.init();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
